﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ef.ServiceImplement
{
    public class UserService : ServiceBase, ef.ServiceInterface.IUserService
    {
        DataProvider.IUserBaseRepository iUserBaseRepository = null;
        public UserService()
        {
            iUserBaseRepository = (SQLServerProvider.UserBaseRepository)base.LoadRepository("ef.SQLServerProvider.UserBaseRepository");
        }

        #region IUserService 成员

        public void RegisterUser(Entity.UserBase_Ext entity)
        {
            iUserBaseRepository.Insert(entity);
        }

        public void DelUser(int? userID)
        {
            if (userID.HasValue)
                iUserBaseRepository.delete(iUserBaseRepository.GetModel().FirstOrDefault(i => i.UserBase.ID == userID.Value));
        }

        public Entity.UserBase_Ext GetUserByID(int? userID)
        {
            if (userID.HasValue)
                return iUserBaseRepository.GetModel().FirstOrDefault(i => i.UserBase.ID == userID.Value);
            else
                return null;
        }

        public VCommons.Entity.PagedList<Entity.UserBase_Ext> GetUser(VCommons.Entity.VPredication vp, VCommons.Entity.PagingParam pp)
        {
            return new VCommons.Entity.PagedList<Entity.UserBase_Ext>(iUserBaseRepository.GetModel(), pp.PageIndex, pp.PageSize);
        }

        public void EditUser(Entity.UserBase_Ext entity)
        {
            iUserBaseRepository.update(entity);
        }
        #endregion
    }
}
